package top.purity.framework.rpc;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import top.purity.framework.common.GlobalConstant;
import top.purity.framework.common.TenantContextHolder;

@Slf4j
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        // 在这里添加额外的处理逻辑，添加请求头
        String path = template.path();
        log.info("rpc path : {}", path);
        // 新增 请求头
        Long tenantId = TenantContextHolder.getTenantId();
        if (tenantId != null) {
            template.header(GlobalConstant.TENANT_ID, tenantId.toString());
        }
    }
}
